var ACTION_ADD = 0;
var ACTION_REMOVE = 1;

function AddMembers(oRefreshGrid, sTargetId)
{
if (!sTargetId)
{
return false;
}

var memberXml = "";
var lookupType = "SiteMembers";
var lookupSelectionStatus = "multi";
var oTypesToAdd = SystemUser + "," + Equipment;

var retval = LookupObjects(null, lookupSelectionStatus, lookupType, oTypesToAdd, 0);
var equipment = "";
var users = "";

if (!retval || retval.items.length == 0)
{

return false;
}
else
{
for (i=0; i<retval.items.length; i++)
{
if (retval.items[i].type == Equipment)
{
equipment += retval.items[i].id + ";";
}
else if (retval.items[i].type == SystemUser)
{
users += retval.items[i].id + ";";
}
}

memberXml = "<membership>";
if (equipment.length > 0)
{

equipment = equipment.substr(0, equipment.length-1);
memberXml += "<equipment>" + equipment + "</equipment>";
}

if (users.length > 0)
{

users = users.substr(0, users.length-1);
memberXml += "<users>" + users + "</users>";
}
memberXml += "<site>" + sTargetId + "</site></membership>";

var oXml = CreateXmlDocument(false);
oXml.loadXML(memberXml);

var xmlhttp = CreateXmlHttp();
xmlhttp.open("POST", prependOrgName("/_grid/cmds/cmd_addsitemembers.aspx"), false);
SetTokenInHeader(xmlhttp, prependOrgName("/_grid/cmds/cmd_addsitemembers.aspx"));
xmlhttp.send(oXml);





var oXml = CreateXmlDocument(false);
oXml.loadXML(xmlhttp.responseXML.xml);

if (oRefreshGrid && handleXMLErr(oXml))
{
document.all[oRefreshGrid].Refresh();
}
}
}

function RemoveMembers(sGrid, sGroupId)
{
var aSelectedMembers = getSelected(sGrid);
if (aSelectedMembers.length > 0)
{
if (openStdDlg(prependOrgName("/_grid/cmds/dlg_removesitemembers.aspx?iTotal=") + aSelectedMembers.length, aSelectedMembers, 400, 200))
{
document.all[sGrid].Refresh();
}
}
else
{
alert( LOCID_ACTION_NOITEMSELECTED );
}
}